<template>
  <div class="section-wrap">
    <div class="form-section">
    
      <div class="form-item form-item-style1">
        <div class="label-title">
           <label>姓名<span class="red">*</span></label>
        </div>
        <group>
          <div>
            <input type="text" :placeholder="holder"    v-model="AccidentPerson.UserName"/>
          </div>
        </group>
      </div>
      <div class="form-item form-item-style1">
        <div class="label-title">
          <label>伤害情况（死，伤）</label>
        </div>
        <group>
          <div>
            <input type="text" :placeholder="holder"   v-model="AccidentPerson.bruiseCase"/>
          </div>
        </group>
      </div>
      <div class="form-item form-item-style1">
        <div class="label-title">
          <label>工种及级别</label>
        </div>
        <group>
          <div>
            <input type="text" :placeholder="holder"   v-model="AccidentPerson.profession"/>
          </div>
        </group>
      </div>
      <div class="form-item form-item-style1">
        <div class="label-title">
          <label>性别</label>
        </div>
        <div v-if="this.$route.query.tyof =='1'">
                    <p>{{AccidentPerson.sex}}</p>
                </div>
                 <group v-else>
          <div>
            <popup-picker 
            :data="sexList" 
             placeholder="请选择"  
            :columns="1"
             v-model="selectSex"></popup-picker>
          </div>
        </group>
      </div>
      <div class="form-item form-item-style1">
        <div class="label-title">
          <label>年龄</label>
        </div>
        <group>
          <div>
            <input type="number"  :placeholder="holder"  onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" v-model="AccidentPerson.age"/>
          </div>
        </group>
      </div>
      <div class="form-item form-item-style1">
        <div class="label-title">
          <label>本工种工龄</label>
        </div>
        <group>
          <div>
            <input type="text"  :placeholder="holder"   v-model="AccidentPerson.workAge"/>
          </div>
        </group>
      </div>
      <div class="form-item form-item-style1">
        <div class="label-title">
          <label>受过何种安全教育</label>
        </div>
        <group>
          <div>
            <input type="text"  :placeholder="holder"   v-model="AccidentPerson.SatetyEducationType"/>
          </div>
        </group>
      </div>
      <div class="form-item form-item-style1">
        <div class="label-title">
          <label>估计直接经济损失</label>
        </div>
        <group>
          <div>
            <input type="number" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"  placeholder="请输入" v-model="AccidentPerson.EconomyLoss"/>
          </div>
        </group>
      </div>
     <div class="form-item form-item-style2">
                <div class="label-title space-between">
                    <div class="space-between">
                        <label>备注</label>
                    </div>
                    <span @click="unfoldMeasure = !unfoldMeasure">{{unfoldMeasure?'收起': '展开'}}</span>
                </div>
                <div>
            <textarea :placeholder="holder" :class="{'unfold':unfoldMeasure}" v-model="AccidentPerson.Remark"></textarea>
                   
                </div>
            </div>
       <p class="search-btn" @click="Sure" v-show="this.$route.query.tyof?false:true">确定</p>
      <myMenu></myMenu>
    </div>
  </div>
</template>
<script type="text/javascript">
  import {Tab, TabItem} from 'vux'
  import {personDetails} from '@/api/api'
  import myMenu from '@/commonComponents/menu'

  export default {
    components: {
      Tab,
      TabItem,
      myMenu
    },
    data () {
      return {
        formData:{},
        sexList:['男','女'],
        selectSex:[],
        unfoldMeasure: false, // 展开
        listArr: {},
        userInfo:{},
        param: {
          allowPaging: true,
          pageIndex: 0,
          pageSize: 1000
        },
        AccidentPerson:{
          UserName:'',
          bruiseCase:'',
          profession:'',
          sex:'',
          age:'',
          workAge:'',
          SatetyEducationType:'',
          EconomyLoss:0,
          Remark:'',
          ID:''
        },
        holder:'请输入'
       }
    },
    created () {
      
       this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
       this.formData.departID = this.userInfo.deptid
       this.departsir = this.userInfo.departsir
   
      if (this.$store.state.checkcompany.sourceType !== 'CasualtiesDetail') {
        this.$store.state.checkcompany = {}
      }
      if (localStorage.getItem('listSearch')) {
        this.formData = JSON.parse(localStorage.getItem('listSearch'))
        localStorage.removeItem('listSearch')
        this.formData.departID = this.$store.state.checkcompany.deptId
        this.formData.departName = this.$store.state.checkcompany.deptName
        this.brokenRuleType = this.formData.brokenRuleType
        this.brokenRuleData = this.formData.brokenRuleData
        this.formData.brokenRuleType = null
        
      }
     
       if(this.$route.query.id !=''  && typeof(this.$route.query.id) !='undefined')
        {
           this.AccidentId=this.$route.query.id;
           this.getInfo(this.AccidentId);
        }
    },methods: 
    {
     
        Sure(){
          if (!this.AccidentPerson.UserName) {
          this.$vux.toast.text('请输入姓名')
          return false
        }
           if(this.AccidentPerson.EconomyLoss=='')
           {
this.AccidentPerson.EconomyLoss=0;
           }
          if(this.AccidentId !==undefined && this.AccidentId !='' ) //修改
          {
             
               this.$store.state.personCasualtiesList.forEach((item) => {
               if(item.id == this.AccidentId)
               {
               
                item.sex=this.selectSex.replace('["','').replace('"]','');
                 item=this.AccidentPerson
                  
              }
          })
          }else{ //添加
       
          this.AccidentPerson.ID=this.getRandomInt(1,100)
          
          this.AccidentPerson.sex=this.selectSex[0];
          this.$store.state.personCasualtiesList.push(this.AccidentPerson);  
          }
          this.$router.back(-1);
        },
        getRandomInt(min, max)
        {
            return Math.floor(Math.random() * (max - min + 1)) + min;
        },
        getInfo(val)
        {
         this.holder=''; 
           let noelist= JSON.parse(localStorage.getItem("nowaccpeptList"));
            noelist.forEach((item,index) => {
              if(item.ID == val)
              {
                 
                  this.AccidentPerson=item;
                  
              }
          })
       
        }
    }
  }
</script>
<style lang="less" scoped>
  @import '~vux/src/styles/1px.less';
  @import '~vux/src/styles/center.less';
 .search-btn {
      width: 200px;
      line-height: 40px;
      border-radius: 20px;
      margin: 23px auto;
      text-align: center;
      color: #fff;
      background: #2269ff;
    }
    .search-btn:hover {
      opacity: 8;
    }
  .form-section {
    .vux-tab-selected {
      i {
        font-size: 15px;
        color: #2269ff;
        font-weight: bold;
      }
    }
  }
  input{
    text-align: right;
    font-size: 12px;
  }
  .red{
    color: red;
  }
</style>
